<?php
namespace app\admin\controller;
use app\common\controller\Common;
use app\admin\model\OrderModel;
use app\admin\model\AfterModel;
use app\common\model\Category;
use app\common\model\Shop;
use think\Exception;
use think\Request;
class Order extends Common
{
	/**
    * 交易管理
    */
    public function order()
    {
        if(request()->isPost())
		{
			$info = Request::instance()->param();
			return OrderModel::getOrderGoods($info);
		}
        $this->assign('shop',(new Shop())->shopList(['is_show'=>0],'shop_id,shop_name'));
        return $this->fetch();
    }
    /**
    * 订单管理
    */
    public function orderlist()
    {
        $info = [];
        if(request()->isPost())
		{
			$info = Request::instance()->param();
		}
        list($order,$xsdd,$xsze,$dfk) = OrderModel::getOrderList($info);
        $this->assign('order',$order);
        $this->assign('fcat',(new Category())->categoryList(['fid'=>0],'category_id,category_name'));
        $this->assign('shop',(new Shop())->shopList(['is_show'=>0],'shop_id,shop_name'));
        /*销售订单数*/
        $this->assign('xsdd',$xsdd);
        /*销售总额*/
        $this->assign('xsze',$xsze);
        /*待付款总额*/
        $this->assign('dfk',$dfk);
        return $this->fetch();
    }
    /**
    * 订单详情
    */
    public function orderinfo()
    {
        $info = Request::instance()->param();
        list($order,$OrderGoods,$OrderActivity) = OrderModel::orderInfo($info);
        
        $this->assign('order',$order);
        $this->assign('ordergoods',$OrderGoods);
        $this->assign('orderactivity',$OrderActivity);
        return $this->fetch();
    }
    /**
    * 退货、召回管理
    */
    public function orderafterlist()
    {
        $info = Request::instance()->param();
        list($order,$thdd,$thze) = AfterModel::getAfterList($info);
        $this->assign('order',$order);
        $this->assign('fcat',(new Category())->categoryList(['fid'=>0],'category_id,category_name'));
        /*退货订单数*/
        $this->assign('thdd',$thdd);
        /*退货总金额*/
        $this->assign('thze',$thze);
        /*类型*/
        $this->assign('ty',$info['ty']);
        $this->assign('shop',(new Shop())->shopList(['is_show'=>0],'shop_id,shop_name'));
        return $this->fetch();
    }
    /**
    * 咨询管理
    */
    public function consultlist()
    {
        if(request()->isPost())
		{
			try{
				$info = Request::instance()->param();
				return json(AfterModel::getConsultList($info));
			}catch (\Exception $e){
				return json(back(config('state.STATUS_CODE_FOURONE'),$e->getMessage()));
			}
		}
        $this->assign('fcat',(new Category())->categoryList(['fid'=>0],'category_id,category_name'));
        $this->assign('shop',(new Shop())->shopList(['is_show'=>0],'shop_id,shop_name'));
        return $this->fetch();
    }
}